package org.example.messagewallplus.service;

import org.example.messagewallplus.mapper.MessageInfoMapper;
import org.example.messagewallplus.model.MessageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class MessagewallSevice {

    @Autowired
    MessageInfoMapper mapper;

    public List<MessageInfo> getMessageInfo() {
        return mapper.getMessageInfo();
    }

    public boolean publish(MessageInfo messageInfo) {
        System.out.println(messageInfo);
        if (StringUtils.hasLength(messageInfo.getTo()) && StringUtils.hasLength(messageInfo.getFrom()
        ) && StringUtils.hasLength(messageInfo.getMessage())) {
            mapper.insertMessageInfo(messageInfo);
            return true;
        }
        return false;
    }
}